import React, { useState, useRef, useContext, createContext } from 'react'

const numcontext = createContext()
function Son(props) {
    const {msg} = useContext(numcontext)
    return (
        <ul>
            {
                msg.map((item, i) => <li key={i}>{item}</li>)
            }
        </ul>

    )
}
function Father(props) {
    const { fval } = props
    return <Son  >我是父级组件 </Son>
}
export default function Context00(props) {
    let [msg, setMsg] = useState([111, 222, 333])
    const myin = useRef();
    const add = () => {
        let val = myin.current.value;
        let news =[...msg]
        news.push(val);
        console.log(news)
        setMsg(news)
    }
    return (
        <div>
            <input ref={myin} type="text" />
            <button onClick={add} >添加</button>
            <numcontext.Provider value={{msg}}>
                <Father   ></Father>
            </numcontext.Provider>
        </div>
    )
}

